jQuery(document).ready(function($) {
	  $('#email, #username').blur(function() {
      var email = $('#email').val();
	  var username = $('#username').val();
	  var bbs_web_root = $('#bbs_web_root').val();
	  $('div.Messages').remove();
      if (username != '' || email != '') {
        var checkUrl = bbs_web_root + 'action/front/do_member?action=check_member&username='+encodeURIComponent(username)+'&email='+encodeURIComponent(email)+'&number='+Math.random();
         $.ajax({
            type: "GET",
            url: checkUrl,
            dataType: 'text',
            success: function(text) {
               if (text == '1'){
			    var message = $.cookie('sysinfo');
                $('div.Messages').remove();
				$('<div class="Messages Information"><ul><li>' + message + '</li></ul></div>').appendTo('body').show();
				$('#signup').attr('disabled',true);
               }else{
				$('#signup').attr('disabled',false);
			   }
            }
         });
      }
   });
	 $('#signup').click(function() {
		var username = $.trim($('#username').val());
		var email = $.trim($('#email').val());
		var password = $.trim($('#password').val());
		var passwordmatch = $.trim($('#passwordmatch').val());
		var bbs_web_root = $.trim($('#bbs_web_root').val());
		var btn = this;

		if(email==''){
			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '请输入Email！' + '</li></ul></div>').appendTo('body').show();
			return;
		}
		if(username==''){
			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '请输入用户名！' + '</li></ul></div>').appendTo('body').show();
			return;
		}
		if(password==''){
			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '请输入密码！' + '</li></ul></div>').appendTo('body').show();
			return;
		}
		if(password!=passwordmatch){
			$('div.Messages').remove();
			$('<div class="Messages Information"><ul><li>' + '两次输入的密码不一致,请重新输入！' + '</li></ul></div>').appendTo('body').show();
			return;
		}
		$.ajax({
		type: "POST",
		url:"action/front/do_member.php?action=new_register",
			dataType: "",
			data:{'email': email,'username': username,'password':password},
			success: function(data) {
				location.href=bbs_web_root;
			}
		});
	 });

});